package com.fzg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fzg.common.enums.ResponseWrapper;
import com.fzg.common.model.user.param.GetCurrentUserJobInfoParam;
import com.fzg.common.model.user.result.GetCurrentUserAllJobInfoResult;
import com.fzg.common.tool.CommonTool;
import com.fzg.entity.User;
import com.fzg.entity.UserJob;
import com.fzg.mapper.UserJobMapper;
import com.fzg.mapper.UserMapper;
import com.fzg.service.UserJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户求职表 服务实现类
 * </p>
 *
 * @author fzg
 * @since 2021-12-13
 */
@Service
public class UserJobServiceImpl extends ServiceImpl<UserJobMapper, UserJob> implements UserJobService {

    @Autowired
    private UserJobMapper userJobMapper;

    @Autowired
    private UserMapper userMapper;

    /**
     * 获取所有求职信息
     *
     * @return ResponseWrapper
     */
    @Override
    public ResponseWrapper getAllJobInfo() {
        ArrayList<UserJob> userJobs1 = new ArrayList<>();
        List<UserJob> userJobs = userJobMapper.selectList(null);
        if (userJobs.size()>0){
            return ResponseWrapper.markSuccess(userJobs);
        }else {
            return ResponseWrapper.markSuccess(userJobs1);
        }
    }

    /**
     * 得到当前用户发布的求职信息
     *
     * @param param 参数
     * @return ResponseWrapper
     */
    @Override
    public ResponseWrapper getCurrentUserJobInfo(GetCurrentUserJobInfoParam param) {
        // 根据账号查询用户aid
        User user = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getAccountNumber, param.getAccount()));

        List<Map<String, Object>> infoListMap = userMapper.getCurrentUserAllJobInfo(user.getAid());
        List<GetCurrentUserAllJobInfoResult> infoList = CommonTool.mapListToBeanList(infoListMap, GetCurrentUserAllJobInfoResult.class);

        return ResponseWrapper.markSuccess(infoList);
    }
}
